#-*-coding:utf-8 -*-
import sys,os
from PyQt5.QtWidgets import QApplication, QMainWindow,QWidget,QMessageBox,QListView,QDialog
from PyQt5.QtCore import QStringListModel,Qt
from Ui_mon_cfg import Ui_MainWindow
import Ui_login,Ui_TimeSetting,Ui_EnglishClassTime,Ui_RestTime,Ui_GameProc,Ui_AllProc,Ui_MusicProc,Ui_BrowerProc,Ui_UnnormalProc
from Crypto.Hash import SHA256
import json,subprocess
Hash_Salt = b'!!@@SSSTCHash&Salt###'

class base():
    def config_file_write(self,file,json_data):
        """# 将json数据对象写入文件"""
        with open('./db/%s'%file, mode='w',encoding="utf-8") as wf:  
            # ensure_ascii=False 可支持输出中文，indent设置缩进
            json.dump(json_data, wf, ensure_ascii=False, indent=4)  
            
class TimeSetting_UI(base, Ui_TimeSetting.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.time_setting_add)
        self.pushButton_delete.clicked.connect(self.time_setting_delete)
        self.pushButton_save.clicked.connect(self.time_setting_save)
        
        self.listmodel_time_set = QStringListModel()
        self.listmodel_time_set.setStringList(self.config_data["time_arg"])
        self.listView_time_set.setModel(self.listmodel_time_set)
        
    def time_setting_add(self):
        """
        把 编辑栏 lineEdit_time_set 中的 字符添加到 listmodel_time_set 中
        :return:
        """
        txt = self.lineEdit_time_set.text().strip()
        if txt != '':
            row = self.listmodel_time_set.rowCount()
            self.listmodel_time_set.insertRow(row)
            self.listmodel_time_set.setData(self.listmodel_time_set.index(row), txt)
            self.lineEdit_time_set.setText("")
            
    def time_setting_delete(self):
        """删除 listmodel_time_set 中选中的项"""
        index = self.listView_time_set.currentIndex()
        # print(index.row())
        self.listmodel_time_set.removeRow(index.row())
        
    def time_setting_save(self):
        """保存 listmodel_time_set 中的所有项"""
        row_count = self.listmodel_time_set.rowCount()
        time_arg = []
        for i in range(0,row_count):
            index = self.listmodel_time_set.index(i,0)
            text = self.listmodel_time_set.data(index,Qt.DisplayRole)
            time_arg.append(text)
        self.config_data["time_arg"] = time_arg
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
        
class EnglishClassTime_UI(base, Ui_EnglishClassTime.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.english_class_time_add)
        self.pushButton_delete.clicked.connect(self.english_class_time_delete)
        self.pushButton_save.clicked.connect(self.english_class_time_save)
        
        self.listmodel_english_class_time = QStringListModel()
        self.listmodel_english_class_time.setStringList(self.config_data["englishclass_list"])
        self.listView_english_class_time.setModel(self.listmodel_english_class_time)
        
    def english_class_time_add(self):
        """
        把 编辑栏 lineEdit_english_class_time 中的 字符添加到 listmodel_time_set 中
        :return:
        """
        txt = self.lineEdit_english_class_time.text().strip()
        if txt != '':
            row = self.listmodel_english_class_time.rowCount()
            self.listmodel_english_class_time.insertRow(row)
            self.listmodel_english_class_time.setData(self.listmodel_english_class_time.index(row), txt)
            self.lineEdit_english_class_time.setText("")
            
    def english_class_time_delete(self):
        """删除 listmodel_english_class_time 中选中的项"""
        index = self.listView_english_class_time.currentIndex()
        # print(index.row())
        self.listmodel_english_class_time.removeRow(index.row())
        
    def english_class_time_save(self):
        """保存 listmodel_english_class_time 中的所有项"""
        row_count = self.listmodel_english_class_time.rowCount()
        english_class_time = []
        for i in range(0,row_count):
            index = self.listmodel_english_class_time.index(i,0)
            text = self.listmodel_english_class_time.data(index,Qt.DisplayRole)
            english_class_time.append(text)
        self.config_data["englishclass_list"] = english_class_time
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
        
class RestTime_UI(base, Ui_RestTime.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.rest_time_add)
        self.pushButton_delete.clicked.connect(self.rest_time_delete)
        self.pushButton_save.clicked.connect(self.rest_time_save)
        
        self.listmodel_rest_time = QStringListModel()
        self.listmodel_rest_time.setStringList(self.config_data["rest_time"])
        self.listView_rest_time.setModel(self.listmodel_rest_time)
        
    def rest_time_add(self):
        """
        把 编辑栏 lineEdit_english_class_time 中的 字符添加到 listmodel_time_set 中
        :return:
        """
        txt = self.lineEdit_rest_time.text().strip()
        if txt != '':
            row = self.listmodel_rest_time.rowCount()
            self.listmodel_rest_time.insertRow(row)
            self.listmodel_rest_time.setData(self.listmodel_rest_time.index(row), txt)
            self.lineEdit_rest_time.setText("")
            
    def rest_time_delete(self):
        """删除 listmodel_english_class_time 中选中的项"""
        index = self.listView_rest_time.currentIndex()
        # print(index.row())
        self.listmodel_rest_time.removeRow(index.row())
        
    def rest_time_save(self):
        """保存 listmodel_english_class_time 中的所有项"""
        row_count = self.listmodel_rest_time.rowCount()
        rest_time = []
        for i in range(0,row_count):
            index = self.listmodel_rest_time.index(i,0)
            text = self.listmodel_rest_time.data(index,Qt.DisplayRole)
            rest_time.append(text)
        self.config_data["rest_time"] = rest_time
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))

class GameProc_UI(base, Ui_GameProc.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.game_proc_add)
        self.pushButton_delete.clicked.connect(self.game_proc_delete)
        self.pushButton_save.clicked.connect(self.game_proc_save)
        
        self.listmodel_game_proc = QStringListModel()
        self.listmodel_game_proc.setStringList(self.config_data["game_proc"])
        self.listView_game_proc.setModel(self.listmodel_game_proc)
        
    def game_proc_add(self):
        """
        把 编辑栏 lineEdit_english_class_time 中的 字符添加到 listmodel_time_set 中
        :return:
        """
        txt = self.lineEdit_game_proc.text().strip()
        if txt != '':
            row = self.listmodel_game_proc.rowCount()
            self.listmodel_game_proc.insertRow(row)
            self.listmodel_game_proc.setData(self.listmodel_game_proc.index(row), txt)
            self.lineEdit_game_proc.setText("")
            
    def game_proc_delete(self):
        """删除 listmodel_game_proc 中选中的项"""
        index = self.listView_game_proc.currentIndex()
        # print(index.row())
        self.listmodel_game_proc.removeRow(index.row())
        
    def game_proc_save(self):
        """保存 listmodel_game_proc 中的所有项"""
        row_count = self.listmodel_game_proc.rowCount()
        game_proc = []
        for i in range(0,row_count):
            index = self.listmodel_game_proc.index(i,0)
            text = self.listmodel_game_proc.data(index,Qt.DisplayRole)
            game_proc.append(text)
        self.config_data["game_proc"] = game_proc
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
        
class MusicProc_UI(base, Ui_MusicProc.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.music_proc_add)
        self.pushButton_delete.clicked.connect(self.music_proc_delete)
        self.pushButton_save.clicked.connect(self.music_proc_save)
        
        self.listmodel_music_proc = QStringListModel()
        self.listmodel_music_proc.setStringList(self.config_data["music_proc"])
        self.listView_music_proc.setModel(self.listmodel_music_proc)
        
    def music_proc_add(self):
        """
        把 编辑栏 lineEdit_music_proc 中的 字符添加到 listmodel_time_set 中
        :return:
        """
        txt = self.lineEdit_music_proc.text().strip()
        if txt != '':
            row = self.listmodel_music_proc.rowCount()
            self.listmodel_music_proc.insertRow(row)
            self.listmodel_music_proc.setData(self.listmodel_music_proc.index(row), txt)
            self.lineEdit_music_proc.setText("")
            
    def music_proc_delete(self):
        """删除 listmodel_music_proc 中选中的项"""
        index = self.listView_music_proc.currentIndex()
        # print(index.row())
        self.listmodel_music_proc.removeRow(index.row())
        
    def music_proc_save(self):
        """保存 listmodel_music_proc 中的所有项"""
        row_count = self.listmodel_music_proc.rowCount()
        music_proc = []
        for i in range(0,row_count):
            index = self.listmodel_music_proc.index(i,0)
            text = self.listmodel_music_proc.data(index,Qt.DisplayRole)
            music_proc.append(text)
        self.config_data["music_proc"] = music_proc
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
                       
class BrowerProc_UI(base, Ui_BrowerProc.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.brower_proc_add)
        self.pushButton_delete.clicked.connect(self.brower_proc_delete)
        self.pushButton_save.clicked.connect(self.brower_proc_save)
        
        self.listmodel_brower_proc = QStringListModel()
        self.listmodel_brower_proc.setStringList(self.config_data["brower_proc"])
        self.listView_brower_proc.setModel(self.listmodel_brower_proc)
        
    def brower_proc_add(self):
        """
        把 编辑栏 lineEdit_brower_proc 中的 字符添加到 listmodel_brower_proc 中
        :return:
        """
        txt = self.lineEdit_brower_proc.text().strip()
        if txt != '':
            row = self.listmodel_brower_proc.rowCount()
            self.listmodel_brower_proc.insertRow(row)
            self.listmodel_brower_proc.setData(self.listmodel_brower_proc.index(row), txt)
            self.lineEdit_brower_proc.setText("")
            
    def brower_proc_delete(self):
        """删除 listmodel_brower_proc 中选中的项"""
        index = self.listView_brower_proc.currentIndex()
        # print(index.row())
        self.listmodel_brower_proc.removeRow(index.row())
        
    def brower_proc_save(self):
        """保存 listmodel_brower_proc 中的所有项"""
        row_count = self.listmodel_brower_proc.rowCount()
        brower_proc = []
        for i in range(0,row_count):
            index = self.listmodel_brower_proc.index(i,0)
            text = self.listmodel_brower_proc.data(index,Qt.DisplayRole)
            brower_proc.append(text)
        self.config_data["brower_proc"] = brower_proc
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
        
class AllProc_UI(base, Ui_AllProc.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.all_proc_add)
        self.pushButton_delete.clicked.connect(self.all_proc_delete)
        self.pushButton_save.clicked.connect(self.all_proc_save)
        
        self.listmodel_all_proc = QStringListModel()
        self.listmodel_all_proc.setStringList(self.config_data["all_processes"])
        self.listView_all_proc.setModel(self.listmodel_all_proc)
        
    def all_proc_add(self):
        """
        把 编辑栏 lineEdit_brower_proc 中的 字符添加到 listmodel_brower_proc 中
        :return:
        """
        txt = self.lineEdit_all_proc.text().strip()
        row_count = self.listmodel_all_proc.rowCount()
        
        find=False
        for i in range(0,row_count):
            index = self.listmodel_all_proc.index(i,0)
            if txt == self.listmodel_all_proc.data(index,Qt.DisplayRole):
                find = True
                print(QMessageBox.information(self, "提示", "此进程已经存在!", QMessageBox.Yes, QMessageBox.Yes))
                break;
            
        if txt != '' and not find:
            row = self.listmodel_all_proc.rowCount()
            self.listmodel_all_proc.insertRow(row)
            self.listmodel_all_proc.setData(self.listmodel_all_proc.index(row), txt)
        
        self.lineEdit_all_proc.setText("")
            
    def all_proc_delete(self):
        """删除 listmodel_all_proc 中选中的项"""
        index = self.listView_all_proc.currentIndex()
        # print(index.row())
        self.listmodel_all_proc.removeRow(index.row())
        
    def all_proc_save(self):
        """保存 listmodel_all_proc 中的所有项"""
        row_count = self.listmodel_all_proc.rowCount()
        all_proc = []
        for i in range(0,row_count):
            index = self.listmodel_all_proc.index(i,0)
            text = self.listmodel_all_proc.data(index,Qt.DisplayRole)
            all_proc.append(text)
            
        self.config_data["all_processes"].clear()
        for proc in all_proc:
            if not proc in self.config_data["all_processes"]:
                self.config_data["all_processes"].append(proc)
                
        #self.config_data["all_processes"] = all_proc
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))

class UnnormalProc_UI(base, Ui_UnnormalProc.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
        except Exception as e:
            print(e)

        self.pushButton_add.clicked.connect(self.unnormal_proc_add)
        self.pushButton_delete.clicked.connect(self.unnormal_proc_delete)
        # self.pushButton_save.clicked.connect(self.unnormal_proc_save)
        
        self.listmodel_unnormal_proc = QStringListModel()
        self.listmodel_unnormal_proc.setStringList(self.config_data["unnormal_proc"])
        self.listView_unnormal_proc.setModel(self.listmodel_unnormal_proc)
        
    def unnormal_proc_add(self):
        """
        把 编辑栏 lineEdit_unnormal_proc 中的 字符添加到 listmodel_unnormal_proc 中
        :return:
        """
        index = self.listView_unnormal_proc.currentIndex()
        text = self.listmodel_unnormal_proc.data(index,Qt.DisplayRole)
        self.config_data["all_processes"].append(text)
        self.config_data["unnormal_proc"].pop(index.row())
        self.listmodel_unnormal_proc.removeRow(index.row())
        #self.config_data["all_processes"] = list(set(self.config_data["all_processes"]))
        self.config_file_write("config.json",self.config_data)
        print(QMessageBox.information(self, "提示", "添加\'%s\'OK!"%text, QMessageBox.Yes, QMessageBox.Yes))
        # txt = self.lineEdit_unnormal_proc.text().strip()
        # if txt != '':
        #     row = self.listmodel_unnormal_proc.rowCount()
        #     self.listmodel_unnormal_proc.insertRow(row)
        #     self.listmodel_unnormal_proc.setData(self.listmodel_unnormal_proc.index(row), txt)
        #     self.lineEdit_unnormal_proc.setText("")
            
    def unnormal_proc_delete(self):
        """删除 listmodel_all_proc 中选中的项"""
        index = self.listView_unnormal_proc.currentIndex()
        # print(index.row())
        self.listmodel_unnormal_proc.removeRow(index.row())
        self.config_data["unnormal_proc"].pop(index.row())
        self.config_file_write("config.json",self.config_data)
        
    # def unnormal_proc_save(self):
    #     """保存 listmodel_unnormal_proc 中的所有项"""
    #     row_count = self.listmodel_unnormal_proc.rowCount()
    #     unnormal_proc = []
    #     for i in range(0,row_count):
    #         index = self.listmodel_unnormal_proc.index(i,0)
    #         text = self.listmodel_unnormal_proc.data(index,Qt.DisplayRole)
    #         unnormal_proc.append(text)
    #     self.config_data["unnormal_proc"] = unnormal_proc
    #     self.config_file_write("config.json",self.config_data)
    #     print(QMessageBox.information(self, "提示", "保存OK!", QMessageBox.Yes, QMessageBox.Yes))
        
class login_UI(Ui_login.Ui_Form, QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/User.json', 'r',encoding="utf-8") as f:
                self.user_data = json.load(f)
        except Exception as e:
            print(e)
            
        self.lineEdit_pw.setPlaceholderText("password")
        self.lineEdit_id.setPlaceholderText("username")
        self.lineEdit_id.setText("koby")
        self.lineEdit_pw.setText("123456")
        self.pushButton_login.clicked.connect(self.login_verify)
        
    def login_verify(self):
        userid = self.lineEdit_id.text()
        password = self.lineEdit_pw.text()
        if (userid == "" or password == ""):
            print(QMessageBox.warning(self, "警告", "账户和密码不可为空!", QMessageBox.Yes, QMessageBox.Yes))
            return
        password_h = self.hash_encrypt(Hash_Salt,password)
        # print(password_h)
        if not userid in self.user_data:
            print(QMessageBox.information(self, "提示", "该账号不存在!", QMessageBox.Yes, QMessageBox.Yes))
            return
        if password_h != self.user_data[userid]:
            print(QMessageBox.information(self, "提示", "密码错误!", QMessageBox.Yes, QMessageBox.Yes))
            return
        self.accept()
        
    def hash_encrypt(self,salt,data):
        h= SHA256.new()
        h.update(salt)
        h.update(data.encode())
        resultHex = h.hexdigest()
        return resultHex
        
class mon_cfg_UI(base, Ui_MainWindow, QMainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        
        try:
            with open('./db/config.json', 'r',encoding="utf-8") as f:
                self.config_data = json.load(f)
                # print(self.config_data)
            with open('./db/setting.json', 'r',encoding="utf-8") as f0:
                self.setting = json.load(f0)
                # print(self.setting)
        except Exception as e:
            print(e)
            
        # for item in self.config_data['englishclass_list']:
        #     self.comboBox_english_class_time.addItem(item)
        # self.comboBox_english_class_time.setCurrentIndex(1)
        # self.comboBox_english_class_time.setEditable(True)
        
        for item in self.setting['interval_time']:
            self.comboBox_interval_time.addItem(str(item))
        idx = self.setting["interval_time_idx"]
        self.comboBox_interval_time.setCurrentIndex(idx)
        self.comboBox_interval_time.currentIndexChanged.connect(self.interval_time_changed)
        
        status = ["停止","暂停","启动","退出"]
        for item in status:#self.setting['loops']:
            self.comboBox_status.addItem(str(item))
            
        idx = self.setting['loops']
        if idx==0:
            self.comboBox_status.setCurrentIndex(0)
        elif idx==1:
            self.comboBox_status.setCurrentIndex(1)
        elif idx==2:
            self.comboBox_status.setCurrentIndex(2)
            # os.system("run.bat")
        else:
            self.comboBox_status.setCurrentIndex(3)

        self.comboBox_status.currentIndexChanged.connect(self.status_changed)
        
        # for item in self.config_data['time_arg']:
        #     self.comboBox_time_setting.addItem(item)
        # self.comboBox_time_setting.setCurrentIndex(0)
        # self.comboBox_time_setting.setEditable(True)
        
                
        # for item in self.config_data['rest_time']:
        #     self.comboBox_rest_time.addItem(item)
        # self.comboBox_rest_time.setCurrentIndex(0)
        # self.comboBox_rest_time.setEditable(True)
        # self.listmodel_time_setting = QStringListModel()
        # self.listmodel_time_setting.setStringList(self.config_data["time_arg"])
        # self.listView_time_setting.setModel(self.listmodel_time_setting)
        
        # self.listmodel_english_class_time = QStringListModel()
        # weeks= ["星期日:","星期一:","星期二:","星期三:","星期四:","星期五:","星期六:"]
        # # print(weeks)
        # listView = []
        # for i,week in enumerate(weeks):
        #     listView.append(week+self.config_data["englishclass_list"][i])
        # self.listmodel_english_class_time.setStringList(listView)
        # self.listView_english_class_time.setModel(self.listmodel_english_class_time)

        # self.listmodel_rest_time = QStringListModel()
        # self.listmodel_rest_time.setStringList(self.config_data["rest_time"])
        # self.listView_rest_time.setModel(self.listmodel_rest_time)
        
        # self.listView_rest_time.clicked.connect(self.rest_time_clicked)
        
        self.pushButton_time_setting.clicked.connect(self.btn_time_setting_clicked)
        self.pushButton_english_class_time.clicked.connect(self.btn_english_class_time_clicked)
        self.pushButton_rest_time.clicked.connect(self.btn_rest_time_clicked)
        
        self.pushButton_game_proc.clicked.connect(self.btn_game_proc_clicked)
        self.pushButton_music_proc.clicked.connect(self.btn_music_proc_clicked)
        self.pushButton_brower_proc.clicked.connect(self.btn_brower_proc_clicked)
        self.pushButton_all_proc.clicked.connect(self.btn_all_proc_clicked)
        self.pushButton_unnormal_proc.clicked.connect(self.btn_unnormal_proc_clicked)
        
        # self.pushButton_continue.clicked.connect(self.btn_continue_clicked)
        # self.pushButton_stop.clicked.connect(self.btn_stop_clicked)
        # self.pushButton_pause.clicked.connect(self.btn_pause_clicked)
        if self.setting["allow_game"]:
            self.checkBox_allow_game.setChecked(True)
        else:
            self.checkBox_allow_game.setChecked(False)
        self.checkBox_allow_game.clicked.connect(self.allow_game)
        if self.setting["allow_music"]:
            self.checkBox_allow_music.setChecked(True)
        else:
            self.checkBox_allow_music.setChecked(False)
        self.checkBox_allow_music.clicked.connect(self.allow_music)
        if self.setting["allow_brower"]:
            self.checkBox_allow_brower.setChecked(True)
        else:
            self.checkBox_allow_brower.setChecked(False)
        self.checkBox_allow_brower.clicked.connect(self.allow_brower)
        # self.pushButton_save_cfg.clicked.connect(self.btn_savecfg_clicked)
    
    def status_changed(self):
        idx = self.comboBox_status.currentIndex()
        self.setting['loops'] = idx
        self.config_file_write("setting.json",self.setting)
        if idx==0:
            self.plainTextEdit.appendPlainText("Monirot PC Stop...")
        elif idx==1:
            self.plainTextEdit.appendPlainText("Monirot PC Pause...")
        elif idx==2:
            self.plainTextEdit.appendPlainText("Monirot PC Working...")
            os.system("run.bat")
        else:
            self.plainTextEdit.appendPlainText("Monirot PC exit...")
    
    def interval_time_changed(self):
        idx = self.comboBox_interval_time.currentIndex()
        self.setting["interval_time_idx"] = idx
        self.config_file_write("setting.json",self.setting)
        
        txt = self.comboBox_interval_time.currentText()
        self.plainTextEdit.appendPlainText("Set interval time %ss..."%txt)
    def allow_game(self):
        if self.checkBox_allow_game.isChecked():
            self.setting["allow_game"] = 1
            self.plainTextEdit.appendPlainText("allow game enable...")
        else:
            self.setting["allow_game"] = 0
            self.plainTextEdit.appendPlainText("allow game disable...")
        self.config_file_write("setting.json",self.setting)
        
    def allow_music(self):
        if self.checkBox_allow_music.isChecked():
            self.setting["allow_music"] = 1
            self.plainTextEdit.appendPlainText("allow music enable...")
        else:
            self.setting["allow_music"] = 0
            self.plainTextEdit.appendPlainText("allow music disable...")
        self.config_file_write("setting.json",self.setting)
        # self.plainTextEdit.appendPlainText("Monirot PC Continue...")
        
    def allow_brower(self):
        if self.checkBox_allow_brower.isChecked():
            self.setting["allow_brower"] = 1
            self.plainTextEdit.appendPlainText("allow brower enable...")
        else:
            self.setting["allow_brower"] = 0
            self.plainTextEdit.appendPlainText("allow brower disable...")
        self.config_file_write("setting.json",self.setting)
        # self.plainTextEdit.appendPlainText("Monirot PC Stop...")
    #     self.comboBox_status.setCurrentIndex(0)
        
    def btn_time_setting_clicked(self):
        self.plainTextEdit.appendPlainText("time setting config...")
        timesetting = TimeSetting_UI()
        timesetting.setWindowTitle("Time Setting")
        timesetting.show()
        if timesetting.exec_()==QDialog.Accepted:
            pass
        
    def btn_english_class_time_clicked(self):
        self.plainTextEdit.appendPlainText("English class time config...")
        englishclasstime = EnglishClassTime_UI()
        englishclasstime.setWindowTitle("English Class Time")
        englishclasstime.show()
        if englishclasstime.exec_()==QDialog.Accepted:
            pass
        
    def btn_rest_time_clicked(self):
        self.plainTextEdit.appendPlainText("rest time config...")
        resttime = RestTime_UI()
        resttime.setWindowTitle("Rest Time")
        resttime.show()
        if resttime.exec_()==QDialog.Accepted:
            pass

    def btn_game_proc_clicked(self):
        self.plainTextEdit.appendPlainText("Game process config...")
        gameproc = GameProc_UI()
        gameproc.setWindowTitle("Game Process")
        gameproc.show()
        if gameproc.exec_()==QDialog.Accepted:
            pass
        
    def btn_music_proc_clicked(self):
        self.plainTextEdit.appendPlainText("Music process config...")
        musicproc = MusicProc_UI()
        musicproc.setWindowTitle("Music Process")
        musicproc.show()
        if musicproc.exec_()==QDialog.Accepted:
            pass
        
    def btn_brower_proc_clicked(self):
        self.plainTextEdit.appendPlainText("Brower process config...")
        browerproc = BrowerProc_UI()
        browerproc.setWindowTitle("Brower Process")
        browerproc.show()
        if browerproc.exec_()==QDialog.Accepted:
            pass
        
    def btn_all_proc_clicked(self):
        self.plainTextEdit.appendPlainText("All process config...")
        allproc = AllProc_UI()
        allproc.setWindowTitle("All Process")
        allproc.show()
        if allproc.exec_()==QDialog.Accepted:
            pass
        
    def btn_unnormal_proc_clicked(self):
        self.plainTextEdit.appendPlainText("Unnormal process config...")
        unnormalproc = UnnormalProc_UI()
        unnormalproc.setWindowTitle("Unnormal Process")
        unnormalproc.show()
        if unnormalproc.exec_()==QDialog.Accepted:
            pass        

        
    # def btn_savecfg_clicked(self):
    #     row_count = self.listmodel_rest_time.rowCount()
    #     rest_time = []
    #     for i in range(0,row_count):
    #         index = self.listmodel_rest_time.index(i,0)
    #         text = self.listmodel_rest_time.data(index,Qt.DisplayRole)
    #         rest_time.append(text)
    #     self.config_data["rest_time"] = rest_time
        
    #     row_count = self.listmodel_time_setting.rowCount()
    #     time_arg = []
    #     for i in range(0,row_count):
    #         index = self.listmodel_time_setting.index(i,0)
    #         text = self.listmodel_time_setting.data(index,Qt.DisplayRole)
    #         time_arg.append(text)
    #     self.config_data["time_arg"] = time_arg
        
    #     row_count = self.listmodel_english_class_time.rowCount()
    #     englishclass_list = []
    #     for i in range(0,row_count):
    #         index = self.listmodel_english_class_time.index(i,0)
    #         text = self.listmodel_english_class_time.data(index,Qt.DisplayRole)
    #         text = text[4:len(text)]
    #         englishclass_list.append(text)
    #     self.config_data["englishclass_list"] = englishclass_list
        
    #     self.config_file_write("config.json",self.config_data)
    #     self.plainTextEdit.appendPlainText("Save Config done...")
    
    # def rest_time_clicked(self):
    #     row_count = self.listmodel_rest_time.rowCount()
    #     for i in range(0,row_count):
    #         index = self.listmodel_rest_time.index(i,0)
    #         text = self.listmodel_rest_time.data(index,Qt.DisplayRole)
            # print(text)
       # self.listwidget.row() 获得当前被点击的行， self.listwidget.row(index) 获得当前行的元素对象
        # QMessageBox.information(self, "QListView", "select" + self.listView_rest_time[item.row()])
        
    # # 将json数据对象写入文件
    # def config_file_write(self,file,json_data):
    #     with open('./db/%s'%file, mode='w',encoding="utf-8") as wf:  # 以写方式打开json文件
    #         json.dump(json_data, wf, ensure_ascii=False, indent=4)  # ensure_ascii=False 可支持输出中文，indent设置缩进
        
TOOL_VERSION = 'V1.2'
if __name__ == '__main__':
    app = QApplication(sys.argv)
    login = login_UI()
    login.setWindowTitle("登录")
    login.show()
    if login.exec_()==QDialog.Accepted:
        ui = mon_cfg_UI()
        # ui.setWindowState(Qt.WindowMaximized)
        ui.setWindowTitle(TOOL_VERSION)
        ui.show()  # 显示窗体
        sys.exit(app.exec_())